<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OptionsPricing: Quadrature.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OptionsPricing
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_fc5e39b96a4a731194f34224fb7033b5.html">utils</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">Quadrature.py</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">#!/usr/bin/python</span>
<a name="l00002"></a>00002 <span class="comment"># -*- coding: utf-8 -*-</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="comment"># Copyright (c) 2011</span>
<a name="l00005"></a>00005 <span class="comment">#</span>
<a name="l00006"></a>00006 <span class="comment"># Permission is hereby granted, free of charge, to any person obtaining a</span>
<a name="l00007"></a>00007 <span class="comment"># copy of this software and associated documentation files (the &quot;Software&quot;),</span>
<a name="l00008"></a>00008 <span class="comment"># to deal in the Software without restriction, including without limitation</span>
<a name="l00009"></a>00009 <span class="comment"># the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
<a name="l00010"></a>00010 <span class="comment"># and/or sell copies of the Software, and to permit persons to whom the</span>
<a name="l00011"></a>00011 <span class="comment"># Software is furnished to do so, subject to the following conditions:</span>
<a name="l00012"></a>00012 <span class="comment">#</span>
<a name="l00013"></a>00013 <span class="comment"># The above copyright notice and this permission notice shall be included in</span>
<a name="l00014"></a>00014 <span class="comment"># all copies or substantial portions of the Software.</span>
<a name="l00015"></a>00015 <span class="comment">#</span>
<a name="l00016"></a>00016 <span class="comment"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00017"></a>00017 <span class="comment"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00018"></a>00018 <span class="comment"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00019"></a>00019 <span class="comment"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00020"></a>00020 <span class="comment"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00021"></a>00021 <span class="comment"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<a name="l00022"></a>00022 <span class="comment"># SOFTWARE.</span>
<a name="l00023"></a>00023 <span class="comment">#</span>
<a name="l00024"></a>00024 <span class="comment"># Author: Jesus Carrero &lt;j.o.carrero@gmail.com&gt;</span>
<a name="l00025"></a>00025 <span class="comment"># Mountain View, CA</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="keyword">from</span> scipy.special <span class="keyword">import</span> gammaln
<a name="l00028"></a>00028 <span class="keyword">from</span> Polynomials <span class="keyword">import</span> _jacobiP
<a name="l00029"></a>00029 <span class="keyword">import</span> numpy <span class="keyword">as</span> np
<a name="l00030"></a>00030 <span class="keyword">import</span> fileinput
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 
<a name="l00033"></a><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html">00033</a> <span class="keyword">class </span><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html">Quadrature</a>(object):
<a name="l00034"></a>00034     <span class="stringliteral">&quot;&quot;&quot; Base class for all quadrature formulas. &quot;&quot;&quot;</span>
<a name="l00035"></a>00035 
<a name="l00036"></a>00036     __slots__ = [<span class="stringliteral">&#39;m_weights&#39;</span>, <span class="stringliteral">&#39;m_points&#39;</span>, <span class="stringliteral">&#39;m_order&#39;</span>, <span class="stringliteral">&#39;m_data&#39;</span>]
<a name="l00037"></a>00037 
<a name="l00038"></a><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a48b3480dc3e8352aacd676b35a26e813">00038</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a48b3480dc3e8352aacd676b35a26e813">__init__</a>(self, points, weights, order):
<a name="l00039"></a>00039         <span class="stringliteral">&quot;&quot;&quot; Base class to handle all quadrature formulas. &quot;&quot;&quot;</span>
<a name="l00040"></a>00040 
<a name="l00041"></a>00041         self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a80ef0ef5d1f82098fd0291565b6f96a0">m_weights</a> = weights
<a name="l00042"></a>00042         self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a789e63b3762b2dc25b0db18b368bbb14">m_points</a> = points
<a name="l00043"></a>00043         self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#aead5b0efbe7d465cab554d44bf35b2ef">m_order</a> = order
<a name="l00044"></a>00044         self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#acc129a7827f38a02ce7fc7127885b549">m_data</a> = zip(points, weights)
<a name="l00045"></a>00045 
<a name="l00046"></a><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#aa0d69b5789b7719c89581bdc718955ac">00046</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#aa0d69b5789b7719c89581bdc718955ac">__call__</a>(self, func):
<a name="l00047"></a>00047         <span class="stringliteral">&quot;&quot;&quot;Integrate the callable f with respect to the given quadrature rule.</span>
<a name="l00048"></a>00048 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00049"></a>00049 
<a name="l00050"></a>00050         <span class="keywordflow">return</span> sum(w * func(x) <span class="keywordflow">for</span> (x, w) <span class="keywordflow">in</span> self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#acc129a7827f38a02ce7fc7127885b549">m_data</a>)
<a name="l00051"></a>00051 
<a name="l00052"></a><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a7171853ad4d181c9f7675b2e9706ae1c">00052</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a7171853ad4d181c9f7675b2e9706ae1c">get_order</a>(self):
<a name="l00053"></a>00053         <span class="stringliteral">&quot;&quot;&quot; return quadrature order. &quot;&quot;&quot;</span>
<a name="l00054"></a>00054 
<a name="l00055"></a>00055         <span class="keywordflow">return</span> self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#aead5b0efbe7d465cab554d44bf35b2ef">m_order</a>
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a019dc3f79128eda62234dbcc610cd11e">00057</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a019dc3f79128eda62234dbcc610cd11e">get_weights</a>(self):
<a name="l00058"></a>00058         <span class="stringliteral">&quot;&quot;&quot; quad weights. &quot;&quot;&quot;</span>
<a name="l00059"></a>00059 
<a name="l00060"></a>00060         <span class="keywordflow">return</span> self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a80ef0ef5d1f82098fd0291565b6f96a0">m_weights</a>
<a name="l00061"></a>00061 
<a name="l00062"></a><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#ad3bdb3d97d4dccba3921d31fdad92551">00062</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#ad3bdb3d97d4dccba3921d31fdad92551">get_qpoints</a>(self):
<a name="l00063"></a>00063         <span class="stringliteral">&quot;&quot;&quot; quadrature points. &quot;&quot;&quot;</span>
<a name="l00064"></a>00064 
<a name="l00065"></a>00065         <span class="keywordflow">return</span> self.<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html#a789e63b3762b2dc25b0db18b368bbb14">m_points</a>
<a name="l00066"></a>00066 
<a name="l00067"></a>00067 
<a name="l00068"></a><a class="code" href="classutils_1_1Quadrature_1_1Simplex2DQuadrature.html">00068</a> <span class="keyword">class </span><a class="code" href="classutils_1_1Quadrature_1_1Simplex2DQuadrature.html">Simplex2DQuadrature</a>(<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html">Quadrature</a>):
<a name="l00069"></a>00069     <span class="stringliteral">&quot;&quot;&quot; 2D quadrature formulas for triangles. &quot;&quot;&quot;</span>
<a name="l00070"></a>00070 
<a name="l00071"></a><a class="code" href="classutils_1_1Quadrature_1_1Simplex2DQuadrature.html#a5ff8734ffefa6c8d3765b02dac2695d6">00071</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1Simplex2DQuadrature.html#a5ff8734ffefa6c8d3765b02dac2695d6">__init__</a>(self, order):
<a name="l00072"></a>00072         <span class="stringliteral">&quot;&quot;&quot; Load quadrature from tables. &quot;&quot;&quot;</span>
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         (nodes, weights) = self.<a class="code" href="classutils_1_1Quadrature_1_1Simplex2DQuadrature.html#a911ec9707a22bfe1e757c74a921b88ed">load_quads</a>(order)
<a name="l00075"></a>00075         Quadrature.__init__(self, nodes, weights, order)
<a name="l00076"></a>00076 
<a name="l00077"></a>00077     @staticmethod
<a name="l00078"></a><a class="code" href="classutils_1_1Quadrature_1_1Simplex2DQuadrature.html#a911ec9707a22bfe1e757c74a921b88ed">00078</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1Simplex2DQuadrature.html#a911ec9707a22bfe1e757c74a921b88ed">load_quads</a>(order):
<a name="l00079"></a>00079         <span class="stringliteral">&quot;&quot;&quot; load a quadrature formula of the given order from a table &quot;&quot;&quot;</span>
<a name="l00080"></a>00080 
<a name="l00081"></a>00081         <span class="keywordflow">if</span> 1 &gt; order | order &gt; 7:
<a name="l00082"></a>00082             <span class="keywordflow">print</span> <span class="stringliteral">&#39;Choose an quad order between 1 and 7&#39;</span>
<a name="l00083"></a>00083             <span class="keywordflow">return</span>
<a name="l00084"></a>00084 
<a name="l00085"></a>00085         tables = fileinput.input(<span class="stringliteral">&#39;Tables.txt&#39;</span>)
<a name="l00086"></a>00086         <span class="keywordflow">for</span> line <span class="keywordflow">in</span> tables:
<a name="l00087"></a>00087             row = line.split()
<a name="l00088"></a>00088             <span class="keywordflow">if</span> len(row) == 0:
<a name="l00089"></a>00089                 <span class="keywordflow">continue</span>
<a name="l00090"></a>00090             <span class="keywordflow">if</span> line[0] == <span class="stringliteral">&#39;#&#39;</span>:
<a name="l00091"></a>00091                 <span class="keywordflow">continue</span>
<a name="l00092"></a>00092 
<a name="l00093"></a>00093             l = [int(x) <span class="keywordflow">for</span> x <span class="keywordflow">in</span> row]
<a name="l00094"></a>00094             <span class="keywordflow">if</span> l[1] == order:
<a name="l00095"></a>00095                 points = np.zeros((l[2], 2), <span class="stringliteral">&#39;float64&#39;</span>)
<a name="l00096"></a>00096                 weights = np.zeros((l[2], 1), <span class="stringliteral">&#39;float64&#39;</span>)
<a name="l00097"></a>00097                 <span class="keywordflow">for</span> s <span class="keywordflow">in</span> range(0, l[2]):
<a name="l00098"></a>00098                     row = tables.readline().split()
<a name="l00099"></a>00099                     points[s, :] = [float(x) <span class="keywordflow">for</span> x <span class="keywordflow">in</span> (row[0], row[1])]
<a name="l00100"></a>00100                     weights[s] = float(row[2])
<a name="l00101"></a>00101 
<a name="l00102"></a>00102                 <span class="keywordflow">break</span>
<a name="l00103"></a>00103             <span class="keywordflow">else</span>:
<a name="l00104"></a>00104                 <span class="keywordflow">for</span> s <span class="keywordflow">in</span> range(0, l[2]):
<a name="l00105"></a>00105                     row = tables.readline().split()
<a name="l00106"></a>00106 
<a name="l00107"></a>00107         fileinput.close()
<a name="l00108"></a>00108         <span class="keywordflow">return</span> (points, weights)
<a name="l00109"></a>00109 
<a name="l00110"></a>00110 
<a name="l00111"></a><a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html">00111</a> <span class="keyword">class </span><a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html">JacobiGaussQuadrature</a>(<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html">Quadrature</a>):
<a name="l00112"></a>00112 
<a name="l00113"></a>00113     <span class="stringliteral">&quot;&quot;&quot;An M{N}th order Gauss quadrature associated with the Jacobi</span>
<a name="l00114"></a>00114 <span class="stringliteral">    polynomials of type M{(alpha,beta) &gt; -1}</span>
<a name="l00115"></a>00115 <span class="stringliteral"></span>
<a name="l00116"></a>00116 <span class="stringliteral">    C{alpha} and C{beta} may not be -0.5.</span>
<a name="l00117"></a>00117 <span class="stringliteral"></span>
<a name="l00118"></a>00118 <span class="stringliteral">    Integrates on the interval (-1,1).</span>
<a name="l00119"></a>00119 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00120"></a>00120 
<a name="l00121"></a><a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html#ab87dca2f8b2b2870f6e2d49242575597">00121</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html#ab87dca2f8b2b2870f6e2d49242575597">__init__</a>(self, alpha, beta, order):
<a name="l00122"></a>00122         <span class="stringliteral">&quot;&quot;&quot; Look at the book: Spetral Methods. &quot;&quot;&quot;</span>
<a name="l00123"></a>00123 
<a name="l00124"></a>00124         (points, weights) = self.<a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html#ae36516727eada6229c00015325e4576b">compute_weights_and_nodes</a>(order, alpha,
<a name="l00125"></a>00125                 beta)
<a name="l00126"></a>00126         Quadrature.__init__(self, points, weights, 2 * order - 1)
<a name="l00127"></a>00127 
<a name="l00128"></a>00128     @staticmethod
<a name="l00129"></a><a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html#ae36516727eada6229c00015325e4576b">00129</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html#ae36516727eada6229c00015325e4576b">compute_weights_and_nodes</a>(order, alpha, beta):
<a name="l00130"></a>00130         <span class="stringliteral">&quot;&quot;&quot;Return (nodes, weights) for an n-th order Gauss quadrature</span>
<a name="l00131"></a>00131 <span class="stringliteral">        with the Jacobi polynomials of type (alpha, beta).</span>
<a name="l00132"></a>00132 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00133"></a>00133 
<a name="l00134"></a>00134         nodes = np.zeros((order + 1, 1), <span class="stringliteral">&#39;float&#39;</span>)
<a name="l00135"></a>00135         weights = np.zeros((order + 1, 1), <span class="stringliteral">&#39;float&#39;</span>)
<a name="l00136"></a>00136 
<a name="l00137"></a>00137         <span class="keywordflow">for</span> k <span class="keywordflow">in</span> np.linspace(0, order, order + 1, endpoint=<span class="keyword">True</span>):
<a name="l00138"></a>00138             r = -np.cos(np.pi * (2.0 * k + 1.0E0) / (2.0 * order))
<a name="l00139"></a>00139             <span class="keywordflow">if</span> 0 &lt; k:
<a name="l00140"></a>00140                 r = (r + nodes[k - 1]) / 2.0
<a name="l00141"></a>00141             epsilon = 1.0e-16
<a name="l00142"></a>00142             delta = 1.0E0
<a name="l00143"></a>00143             <span class="keywordflow">while</span> epsilon &lt; abs(delta):
<a name="l00144"></a>00144                 s = np.sum(np.array([1 / (r - nodes[m]) <span class="keywordflow">for</span> m <span class="keywordflow">in</span>
<a name="l00145"></a>00145                            np.linspace(0, k, k, <span class="keyword">False</span>)]))
<a name="l00146"></a>00146                 (y, dy, d2y) = _jacobiP(order + 1, alpha, beta, r)
<a name="l00147"></a>00147                 delta = -y / (dy - y * s)
<a name="l00148"></a>00148                 r += delta
<a name="l00149"></a>00149             nodes[k] = r
<a name="l00150"></a>00150 
<a name="l00151"></a>00151         ab1 = alpha + beta + 1.0E0
<a name="l00152"></a>00152         ao1 = alpha + order + 1.0E0
<a name="l00153"></a>00153         bo1 = beta + order + 1.0E0
<a name="l00154"></a>00154         abo1 = ab1 + order
<a name="l00155"></a>00155         aux = ab1 * np.log(2.0) + gammaln(ao1) + gammaln(bo1) \
<a name="l00156"></a>00156             - gammaln(abo1)
<a name="l00157"></a>00157         aux -= np.sum(np.array([np.log(i) <span class="keywordflow">for</span> i <span class="keywordflow">in</span> np.linspace(2,
<a name="l00158"></a>00158                       order, order - 1, <span class="keyword">True</span>)], <span class="stringliteral">&#39;float&#39;</span>))
<a name="l00159"></a>00159         aux = np.exp(aux)
<a name="l00160"></a>00160 
<a name="l00161"></a>00161         <span class="keywordflow">for</span> i <span class="keywordflow">in</span> np.linspace(0, order, order + 1, <span class="keyword">True</span>):
<a name="l00162"></a>00162             (y, dy, d2y) = _jacobiP(order + 1, alpha, beta, nodes[i])
<a name="l00163"></a>00163             weights[i] = aux / ((1.0E0 - nodes[i] ** 2) * dy ** 2)
<a name="l00164"></a>00164 
<a name="l00165"></a>00165         <span class="keywordflow">return</span> (nodes, weights)
<a name="l00166"></a>00166 
<a name="l00167"></a>00167 
<a name="l00168"></a><a class="code" href="classutils_1_1Quadrature_1_1LegendreGaussQuadrature.html">00168</a> <span class="keyword">class </span><a class="code" href="classutils_1_1Quadrature_1_1LegendreGaussQuadrature.html">LegendreGaussQuadrature</a>(<a class="code" href="classutils_1_1Quadrature_1_1JacobiGaussQuadrature.html">JacobiGaussQuadrature</a>):
<a name="l00169"></a>00169 
<a name="l00170"></a>00170     <span class="stringliteral">&quot;&quot;&quot;M{N}th order Gauss quadrature associated with the Legendre polynomials.</span>
<a name="l00171"></a>00171 <span class="stringliteral">    &quot;&quot;&quot;</span>
<a name="l00172"></a>00172 
<a name="l00173"></a>00173     <span class="keyword">def </span>__init__(self, order):
<a name="l00174"></a>00174         JacobiGaussQuadrature.__init__(self, 0, 0, 2 * order - 1)
<a name="l00175"></a>00175 
<a name="l00176"></a>00176 
<a name="l00177"></a><a class="code" href="classutils_1_1Quadrature_1_1TransformedQuadrature1D.html">00177</a> <span class="keyword">class </span><a class="code" href="classutils_1_1Quadrature_1_1TransformedQuadrature1D.html">TransformedQuadrature1D</a>(<a class="code" href="classutils_1_1Quadrature_1_1Quadrature.html">Quadrature</a>):
<a name="l00178"></a>00178 
<a name="l00179"></a>00179     <span class="stringliteral">&quot;&quot;&quot;A quadrature rule on an arbitrary interval M{(a,b)}. &quot;&quot;&quot;</span>
<a name="l00180"></a>00180 
<a name="l00181"></a><a class="code" href="classutils_1_1Quadrature_1_1TransformedQuadrature1D.html#ae0b1cb845a6ef1017aea2be9b2c70c1d">00181</a>     <span class="keyword">def </span><a class="code" href="classutils_1_1Quadrature_1_1TransformedQuadrature1D.html#ae0b1cb845a6ef1017aea2be9b2c70c1d">__init__</a>(self, quad, left, right):
<a name="l00182"></a>00182         <span class="stringliteral">&quot;&quot;&quot;Transform a given quadrature rule `quad&#39; onto an arbitrary</span>
<a name="l00183"></a>00183 <span class="stringliteral">        interval (left, right).</span>
<a name="l00184"></a>00184 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00185"></a>00185 
<a name="l00186"></a>00186         self.<a class="code" href="classutils_1_1Quadrature_1_1TransformedQuadrature1D.html#a38dce4c59ae52904a526da54721a761f">m_left</a> = left
<a name="l00187"></a>00187         self.<a class="code" href="classutils_1_1Quadrature_1_1TransformedQuadrature1D.html#a56002041736926ac6c650ed9c157b2a6">m_right</a> = right
<a name="l00188"></a>00188 
<a name="l00189"></a>00189         length = right - left
<a name="l00190"></a>00190         <span class="keyword">assert</span> length &gt; 0
<a name="l00191"></a>00191         half_length = length / 2
<a name="l00192"></a>00192         Quadrature.__init__(self, [left + (p + 1) / 2 * length <span class="keywordflow">for</span> p <span class="keywordflow">in</span>
<a name="l00193"></a>00193                             quad.m_points], [w * half_length <span class="keywordflow">for</span> w <span class="keywordflow">in</span>
<a name="l00194"></a>00194                             quad.m_weights])
<a name="l00195"></a>00195 
<a name="l00196"></a>00196 
<a name="l00197"></a>00197 <span class="keywordflow">if</span> __name__ == <span class="stringliteral">&#39;__main__&#39;</span>:
<a name="l00198"></a>00198     quad = <a class="code" href="classutils_1_1Quadrature_1_1LegendreGaussQuadrature.html">LegendreGaussQuadrature</a>(4)
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     <span class="keywordflow">print</span> <span class="stringliteral">&#39; ( INFO ) Testing 1D quadrature points &#39;</span>
<a name="l00201"></a>00201     <span class="keywordflow">print</span> <span class="stringliteral">&#39; ( INFO ) This is the quad formula for n = 10&#39;</span>
<a name="l00202"></a>00202     <span class="keywordflow">print</span> <span class="stringliteral">&quot;&quot;&quot; [ qpoints   |   weights ] &quot;&quot;&quot;</span>
<a name="l00203"></a>00203     <span class="keywordflow">print</span> np.c_[quad.get_qpoints(), quad.get_weights()]
<a name="l00204"></a>00204     <span class="keywordflow">print</span> <span class="stringliteral">&quot;&quot;&quot; scaled to [0, 1] &quot;&quot;&quot;</span>
<a name="l00205"></a>00205     <span class="keywordflow">print</span> np.c_[(1.0E0 + quad.m_points) / 2.0, quad.m_weights]
<a name="l00206"></a>00206 
<a name="l00207"></a>00207     <span class="comment"># quad2 = Simplex2DQuadrature( 2 )</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Dec 22 2011 05:17:53 for OptionsPricing by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
